package com.kamikaze;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	
	public LoginServlet() {
		super();
	}
	protected void doGet(HttpServletRequest request, 
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, 
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String user_id = request.getParameter("user_id");
		String user_pw = request.getParameter("user_pw");
		Member member = new Member(user_id, user_pw);
		if(member.login()){
			//查詢有無month salary資料,沒有就新增一筆
			member.csalary(user_id);
			//檢查出勤狀態
			member.check_attendance_status(user_id);
			
			//計算當月薪資
			session.setAttribute("member", member);
			response.sendRedirect("index.jsp");
		}else{
			session.setAttribute("member", member);
			response.sendRedirect("index.jsp?f=9");
		}
	}
}